//科选参数必须放到最后
function getInfo(name: string, age?: number): string {
  if (age) {
    return `${name}---${age}`;
  } else {
    return `${name}---年龄保密`;
  }
}

console.log(getInfo("wxs"));
//可选参数
function getInfo2(name: string, age: number = 30): string {
  if (age) {
    return `${name}---${age}`;
  } else {
    return `${name}---年龄保密`;
  }
}

console.log(getInfo2("wxs", 34));
//剩余参数
function sum(a: number, b: number, c: number, d: number): number {
  return a + b + c + d;
}
console.log("===>", sum(1, 2, 3, 4));
function sum2(...result: number[]): number {
  let sum: number = 0;
  for (let i = 0; i < result.length; i++) {
    sum += result[i];
  }
  return sum;
}
console.log(sum2(1, 1, 2, 2));
function sum3(a: number, ...result: number[]): number {
  let sum: number = a;
  for (let i = 0; i < result.length; i++) {
    sum += result[i];
  }
  return sum;
}
console.log("剩余运算符:", sum3(1, 1, 2, 2));
function sum4(a: number, b: number, ...result: number[]): number {
  let sum: number = a + b;
  for (let i = 0; i < result.length; i++) {
    sum += result[i];
  }
  return sum;
}
console.log("剩余运算符:", sum4(1, 1, 2, 2));
